// Do not remove the include below
#include "PortMonitor.h"
#include "TimerOne.h"
#include "ByteBuffer.h"
#include "HardwareSerial.h"

extern HardwareSerial Serial;

ByteBuffer buffer;

int PORT = A0;

void callback() {
	buffer.put(analogRead(PORT));
}

void setup() {
	Serial.begin(115200);
	Serial.println(SKETCH_NAME);
	Serial.print(" Booting...");
	// Initialize the buffer with a capacity for 256 bytes
	buffer.init(1024);
	Timer1.initialize(1000); // initialize timer1, and set a 1/2 second period
//	Timer1.pwm(9, 512); // setup pwm on pin 9, 50% duty cycle
	Timer1.attachInterrupt(callback); // attaches callback() as a timer overflow interrupt

	// Init serial just to debug
	Serial.println(" OK");
}

void loop() {
	if (buffer.getSize() >= 100) {
		Serial.print("A0:[");
		while (buffer.getSize() > 1) {
			Serial.print(buffer.get(), DEC);
			Serial.print(",");

		}
		Serial.print(buffer.get(), DEC);
		Serial.println("]");
		buffer.clear();
	}

}
